package net.qiqbframework.modelling.domain;


import java.util.Iterator;

public class DefaultBusinessLoaderChain implements BusinessLoaderChain {

    private final Iterator<? extends BusinessIdLoader> chain;

    private final BizIdentifier businessId;

    public DefaultBusinessLoaderChain(Iterator<? extends BusinessIdLoader> chain, BizIdentifier businessId) {
        this.chain = chain;
        this.businessId = businessId;
    }

    @Override
    public Object proceed() throws Exception {
        if (chain.hasNext()) {
            return chain.next().loadAggregateRoot(businessId, this);
        }
        return null;
    }
}
